package com.service.weChatWifiLogin.controller;

import com.service.config.utils.JsonXMLUtils;
import com.service.config.utils.RedisUtil;
import com.service.config.utils.Result;
import com.service.config.utils.UserTokenManager;
import com.service.weChatWifiLogin.dto.ReviewRecordInfoDto;
import com.service.weChatWifiLogin.dto.ShopInfoReviewDto;
import com.service.weChatWifiLogin.dto.SsIdName;
import com.service.weChatWifiLogin.entity.ReviewRecordInfo;
import com.service.weChatWifiLogin.entity.ShopInfoReview;
import com.service.weChatWifiLogin.entity.UserInfo;
import com.service.weChatWifiLogin.service.ReviewRecordInfoService;
import com.service.weChatWifiLogin.service.ShopInfoReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

import static com.service.config.constant.Constant.USER_NOT_LOGIN;

/**
 * (ReviewRecordInfo)表控制层
 *
 * @author makejava
 * @since 2021-06-29 14:42:44
 */
@RestController
@RequestMapping("reviewRecordInfo")
@Api(tags = "审核管理接口")
public class ReviewRecordInfoController {
    /**
     * 服务对象
     */
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private ShopInfoReviewService shopInfoReviewService;
    /**
     * 通过主键查询单条数据
     *
     * @param cloudAuthToken
     * @return 单条数据
     */
    @GetMapping(value = "queryShopInfoReviews",produces="application/json")
    @ApiOperation(value = "查询审核中,店铺名和ssid名称")
    @ResponseBody
    public Result queryShopInfoReviews(@RequestHeader(value = "token",required = false) String cloudAuthToken,
                                       @RequestParam(value = "flag",required = false)  @ApiParam("1--代表查询审核中 2--审核失败和审核成功 null或者其它数字查询所有") String flag) throws Exception {
        if (redisUtil.exist(cloudAuthToken)) {
            List<ShopInfoReviewDto> shopInfoReviewList = shopInfoReviewService.queryAll(new ShopInfoReview(),flag);
            return Result.ok().setData(shopInfoReviewList);
       }
        return Result.failure(USER_NOT_LOGIN,"用户未登录");
    }
    /**
     * 开始审核
     *
     * @param cloudAuthToken
     * @return 单条数据
     */
    @PostMapping(value = "queryShopInfoReviews",produces="application/json")
    @ApiOperation(value = "开始审核")
    @ResponseBody
    public Result verifyShopInfo(@RequestHeader(value = "token",required = false) String cloudAuthToken,
                                 @RequestParam(value = "flag")  @ApiParam("1--全通过（代表审核成功） 2--不全通过（代表审核失败）") String flag,
                                 @RequestParam(value = "shopId")  @ApiParam("店铺id") String shopId,
                                 @RequestBody ReviewRecordInfoDto reviewRecordInfoDto ) throws Exception {
        if (redisUtil.exist(cloudAuthToken)) {
            shopInfoReviewService.verifyShopInfo(redisUtil.getValue(cloudAuthToken),shopId,flag,reviewRecordInfoDto);
            return Result.ok();
        }
        return Result.failure(USER_NOT_LOGIN,"用户未登录");
    }
    /**
     * 开始审核
     *
     * @param cloudAuthToken
     * @return 单条数据
     */
    @PostMapping(value = "queryShopInfoReview",produces="application/json")
    @ApiOperation(value = "开始审核")
    @ResponseBody
    public Result queryShopInfoReviews(@RequestHeader(value = "token",required = false) String cloudAuthToken,
                                 @RequestParam(value = "flag")  @ApiParam("1--全通过（代表审核成功） 2--不全通过（代表审核失败）") String flag,
                                 @RequestParam(value = "shopId")  @ApiParam("店铺id") String shopId,
                                 @RequestBody ReviewRecordInfoDto reviewRecordInfoDto ) throws Exception {
        if (redisUtil.exist(cloudAuthToken)) {
            shopInfoReviewService.verifyShopInfo(redisUtil.getValue(cloudAuthToken),shopId,flag,reviewRecordInfoDto);
            return Result.ok();
        }
        return Result.failure(USER_NOT_LOGIN,"用户未登录");
    }
}
